Skip to content

fix: compose up must exit non-zero when the AI debugger runs - #2228

Merged
lionello merged 1 commit into
mainfrom
fix/2227-compose-up-exit-code
Aug 21, 2026
Merged

fix: compose up must exit non-zero when the AI debugger runs#2228
lionello merged 1 commit into
mainfrom
fix/2227-compose-up-exit-code

Conversation

@defangdevs

@defangdevs defangdevs commented Aug 21, 2026

Copy link
Copy Markdown
Contributor

Fixes #2227.

The bug

handleComposeUpErr returned the debugger's error:

return debugger.DebugDeploymentError(ctx, debug.DebugConfig{Project: project}, originalErr)

promptAndTrackDebugSession returns nil once the debug session finishes, so a
fatal ComposeUp error came back as nil and the CLI exited 0.

It only bites accounts that auto-approve the debugger. The guard above it,
if global.NonInteractive && !debugger.AutoApprove(), sends free-tier CI
straight out with the error — so the false green hits exactly the paid accounts
whose CI runs the debugger unattended, including Defang's own.

The fix

Run the debugger for its side effect and always return the deployment error.
That is the shape the neighbouring paths already use: handleTailAndMonitorErr
returns nothing and its caller returns deploymentErr, and session.go returns
loadErr after DebugComposeLoadError.

handleTooManyProjectsError still returns nil after a successful interactive
compose down — that one is a deliberate recovery, and it is untouched.

Tests

TestHandleComposeUpErrKeepsTheDeploymentError covers the CI auto-approve path
for both a debugger that succeeds and one that fails;
TestHandleComposeUpErrWithoutAutoApprove covers the free-tier path. Reverting
the one-line change fails the first with expected the original deployment error, got <nil> — the reported symptom exactly.

NewDebuggerForTest is new: NewDebugger needs a live Fabric connection, so
tests outside pkg/debug had no way to build a Debugger.

🤖 Generated with Claude Code

https://claude.ai/code/session_01T3WmpdY3zc555sNdkY9dzQ

Summary by CodeRabbit

  • Bug Fixes
    • Deployment failures now consistently return the original error, even when automated debugging is enabled.
    • Debugger issues no longer mask failed deployments or incorrectly produce successful command exits.
    • Improved error handling across both automatic and non-automatic debugging flows.

handleComposeUpErr returned the DEBUGGER's error. The debugger returns nil once
it has explained the failure, so any fatal ComposeUp error became exit code 0
for accounts that auto-approve the debugger — which is exactly the paid accounts
whose CI runs it unattended. The deploy step went green on a deploy that never
happened; only a downstream smoke test noticed.

Run the debugger for its side effect and always return the deployment error, the
same shape session.go already uses for compose load errors.

Fixes #2227

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@defangdevs
defangdevs requested a review from lionello as a code owner August 21, 2026 15:56
@coderabbitai

coderabbitai Bot commented Aug 21, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 5b7cee71-60c8-4700-b49a-c3a2f2798022

📥 Commits

Reviewing files that changed from the base of the PR and between d8aa2a0 and 81bdb17.

📒 Files selected for processing (3)
  • src/cmd/cli/command/compose.go
  • src/cmd/cli/command/compose_test.go
  • src/pkg/debug/debug.go

Included review availability: Your plan provides up to 2 included reviews per hour; 1 remains after this review.


📝 Walkthrough

Walkthrough

The compose error handler now returns the deployment error after debugger execution. Debugger failures are logged. Tests cover auto-approve and non-auto-approve account paths using an injectable debugger agent.

Changes

Compose error preservation

Layer / File(s) Summary
Preserve deployment errors
src/cmd/cli/command/compose.go
handleComposeUpErr logs debugger failures and always returns the original compose deployment error.
Regression coverage and test debugger construction
src/pkg/debug/debug.go, src/cmd/cli/command/compose_test.go
NewDebuggerForTest enables debugger injection. Tests verify deployment error preservation and debugger invocation behavior for auto-approve and non-auto-approve paths.

Estimated code review effort: 2 (Simple) | ~10 minutes

Merge Risk: ⚪ Minimal · up to 81bdb

The CLI will now exit non-zero when compose deployment fails even if the AI debugger runs; the localized change is covered by focused tests, and no actionable merge-blocking risk remains.

Suggested reviewers: lionello

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 42.86% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 7 functions across 3 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly describes the fix that prevents compose up from exiting successfully after the AI debugger runs.
Linked Issues check ✅ Passed The change preserves the deployment error and adds regression tests for the affected debugger paths described in issue #2227.
Out of Scope Changes check ✅ Passed The production fix, regression tests, and test-only debugger constructor all support the requirements in issue #2227.
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/2227-compose-up-exit-code

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@lionello
lionello merged commit bd55787 into main Aug 21, 2026
15 checks passed
@lionello
lionello deleted the fix/2227-compose-up-exit-code branch August 21, 2026 16:32
defangdevs added a commit that referenced this pull request Aug 22, 2026
main gained #2228 (compose up must exit non-zero when the AI debugger runs),
which touches the same functions as the review fixes on this branch.

Kept main's fix: the debugger runs for its side effect and handleComposeUpErr
returns the original error. Its regression test survives the reconciliation and
still fails with "got <nil>" if the fix is reverted.

Reconciled the removal of the paid-tier gate with that test's needs. The gate is
gone, so the debugger is no longer built at all when there is nobody to prompt,
but #2228 needs it injectable to test how the caller handles its result. The
handlers now take a debuggerFactory that is only called once the caller knows it
will use one, which satisfies both: no agent connection in CI, and a stub in
tests. NewDebuggerForTest loses its defaultPermission argument.

TestHandleComposeUpErrWithoutAutoApprove becomes
TestHandleComposeUpErrNonInteractiveSkipsTheDebugger: with no tier gate, the
thing worth asserting is that CI never builds a debugger, and still gets the
deployment error.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01T3WmpdY3zc555sNdkY9dzQ
@defangdevs defangdevs mentioned this pull request Aug 22, 2026
3 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

compose up exits 0 when the AI debugger auto-runs after a fatal error (false-green CI deploys)

2 participants